class Comic {
  final String id;
  final String title;
  final String author;
  final String description;
  final String coverImageUrl;
  final List<String> genres;
  final double rating;
  final int chaptersCount;
  final String status; // ongoing, completed, hiatus
  final DateTime lastUpdated;
  final bool isPremium;

  const Comic({
    required this.id,
    required this.title,
    required this.author,
    required this.description,
    required this.coverImageUrl,
    required this.genres,
    required this.rating,
    required this.chaptersCount,
    required this.status,
    required this.lastUpdated,
    this.isPremium = false,
  });

  factory Comic.fromJson(Map<String, dynamic> json) {
    return Comic(
      id: json['id'] ?? '',
      title: json['title'] ?? '',
      author: json['author'] ?? '',
      description: json['description'] ?? '',
      coverImageUrl: json['coverImageUrl'] ?? '',
      genres: List<String>.from(json['genres'] ?? []),
      rating: (json['rating'] ?? 0.0).toDouble(),
      chaptersCount: json['chaptersCount'] ?? 0,
      status: json['status'] ?? 'ongoing',
      lastUpdated: DateTime.parse(json['lastUpdated'] ?? DateTime.now().toIso8601String()),
      isPremium: json['isPremium'] ?? false,
    );
  }

  Map<String, dynamic> toJson() {
    return {
      'id': id,
      'title': title,
      'author': author,
      'description': description,
      'coverImageUrl': coverImageUrl,
      'genres': genres,
      'rating': rating,
      'chaptersCount': chaptersCount,
      'status': status,
      'lastUpdated': lastUpdated.toIso8601String(),
      'isPremium': isPremium,
    };
  }
}

class Chapter {
  final String id;
  final String comicId;
  final int number;
  final String title;
  final List<String> pageUrls;
  final DateTime publishDate;
  final bool isPremium;

  const Chapter({
    required this.id,
    required this.comicId,
    required this.number,
    required this.title,
    required this.pageUrls,
    required this.publishDate,
    this.isPremium = false,
  });

  factory Chapter.fromJson(Map<String, dynamic> json) {
    return Chapter(
      id: json['id'] ?? '',
      comicId: json['comicId'] ?? '',
      number: json['number'] ?? 0,
      title: json['title'] ?? '',
      pageUrls: List<String>.from(json['pageUrls'] ?? []),
      publishDate: DateTime.parse(json['publishDate'] ?? DateTime.now().toIso8601String()),
      isPremium: json['isPremium'] ?? false,
    );
  }
}
